package com.tjbank.cssys.web.controller;

import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;


import com.tjbank.cssys.web.config.GetUserCodeFromToken;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import com.tjbank.cssys.framework.base.api.BaseController;
import com.tjbank.cssys.framework.base.api.Response;
import com.tjbank.cssys.api.PermissionService;
import com.tjbank.cssys.dto.PermissionDTO;

import java.util.Date;
import java.util.UUID;

/**
 * 菜单权限
 * 
 * Package : com.tansun.magicube.iam.web.controller
 * 
 * @author -- lijiangtao 2020年5月9日 下午6:47:44
 *
 */
@RestController
public class PermissionController extends BaseController {

	@Autowired
	private PermissionService permissionService;
	private static Logger logger = LoggerFactory.getLogger(PermissionController.class);
	/**
	 * 新增
	 * 
	 * @param permissionDTO
	 * @return
	 * @author -- lijiangtao 2020年5月9日 下午6:56:11
	 */
	@PostMapping("/permission")
	public Response<?> addPermission(@RequestBody @Valid PermissionDTO permissionDTO , HttpServletRequest request) {

		return this.success(permissionService.addPermission(permissionDTO));
	}

	/**
	 * 权限
	 * 
	 * @param permissionDTO
	 * @return
	 * @author -- lijiangtao 2020年7月24日 上午10:19:37
	 */
	@GetMapping("/permission/tree")
	public Response<?> permissionTreeList(PermissionDTO permissionDTO ,HttpServletRequest request) {


		return this.success(permissionService.permissionTreeList(permissionDTO));
	}

	/**
	 * 编辑
	 * 
	 * @param permissionDTO
	 * @return
	 * @author -- lijiangtao 2020年6月21日 下午7:50:55
	 */
	@PutMapping("/permission")
	public Response<?> updatePermission(@RequestBody @Valid PermissionDTO permissionDTO ,HttpServletRequest request) {

		return this.success(permissionService.updatePermission(permissionDTO));
	}

	/**
	 * 删除权限
	 * 
	 * @param permissionId
	 * @return
	 * @author -- lijiangtao 2020年6月21日 下午7:50:47
	 */
	@DeleteMapping("/permission/{permissionId}")
	public Response<?> deletePermission(@PathVariable String permissionId , HttpServletRequest request) {
		return this.success(permissionService.deletePermission(permissionId));
	}
}
